package com.hotel.homehotel.before.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotel.homehotel.before.entiy.Room;
import com.hotel.homehotel.before.entiy.UserHobby;
import com.hotel.homehotel.before.mapper.RoomMapper;
import com.hotel.homehotel.before.mapper.UserHobbyMapper;
import com.hotel.homehotel.before.service.UserHobbyService;
import net.bytebuddy.build.RepeatedAnnotationPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@Service
public class  UserHobbyServiceImpl implements UserHobbyService {
        @Autowired
    UserHobbyMapper userHobbyMapper;

    public   List<Room> Sort(List<Room> rooms, String uid){
        QueryWrapper<UserHobby> queryWrapper=new QueryWrapper();
        queryWrapper.eq("uid",uid);
        queryWrapper.orderByDesc("num");
        System.out.println(uid+"dddddddddddddddd");
        List<UserHobby> userHobbies = userHobbyMapper.selectList(queryWrapper);
        List<Room> list=new ArrayList<>();
        for(UserHobby s:userHobbies)
        {

                Iterator<Room> iterator = rooms.iterator();
                 while(iterator.hasNext())
            {
                if(iterator.next().getId().equals(s.getRid())){
                    list.add(iterator.next());
                    rooms.remove(iterator.next());
                }
            }
        }
         list.addAll(rooms);
        return  list;
    }
}
